<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>货品信息</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="/static/wx/lib/sui/sm.min.css">
    <link rel="stylesheet" href="/static/wx/lib/sui/sm-extend.min.css">
    <link rel="stylesheet" href="/static/wx/css/reset.css">
    <link rel="stylesheet" href="/static/wx/css/main.css">
    <link rel="stylesheet" href="/static/wx/css/public_main.css">
</head>

<body>
    <div class="page-group">
        <div class="page page-current" id="editCommodity">
            <!-- 主内容 -->
            <div class="content">
                <div class="bs-box">
                    <div class="bs-box-content">
                        <div class="bs-box-inner">
                            <div class="bs-box-content-item width-link size-m">
                                <div>货品类型</div>
                                <div>
                                    <input placeholder="请选择商品类型" id="good_type"  value="{if isset($info.goods_type_name)}{$info.goods_type_name}{/if}"/>
                                </div>
                            </div>
                            <div class="bs-box-content-item">
                                <p class="size-m">货品名称</p>
                                <div>
                                    <input class="size-m" type="text" placeholder="请填写货品名称" name="goods_name" value="{if isset($info.goods_name)}{$info.goods_name}{/if}"/>
                                </div>
                            </div>
                            <div class="bs-box-content-item">
                                <p class="size-m">数量规格</p>
                                <div>
                                    <input class="size-m" type="text" placeholder="请填写数量规格" name="goods_num" value="{if isset($info.goods_num)}{$info.goods_num}{/if}" />
                                </div>
                            </div>

                            <div class="bs-box-content-item size-m" style="display:flex;justify-content: space-between;padding-right: .5rem;">
                                <div>物品原值</div>
                                <div>
                                    <input type="text" placeholder="请填写物品原值" class="text-r" value="{if isset($info.good_price)}{$info.good_price|floor}{/if}"  name="good_price"/>
                                </div>
                                <div class="pull-right">万元</div>
                            </div>
                            <div class="bs-box-content-item size-m width-link">
                                <div>评估价</div>
                                <div>
                                    <input placeholder="请填写" name="good_pg_price"  value="{if isset($info.good_pg_price)}{$info.good_pg_price |floor}{/if}"/>
                                </div>
                                <div>万元</div>
                            </div>
                        </div>

                    </div>
                </div>
                <input type="hidden" value="{$policy_num}" name ='policy_num'>
                <input type="hidden" value="{$p_id}" name ='p_id'>
                <div class="btn-box">
                    <div class="my-btn" @click="login" style="margin-top: 1rem;" id="submit">
                        <span class="active size-m">保存</span>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type='text/javascript' src='/static/wx/lib/sui/zepto.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='/static/wx/lib/sui/sm.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='/static/wx/lib/sui/sm-extend.min.js' charset='utf-8'></script>
</body>
<script>
    $(function () {
        var n = $('.step-box').children().length;
        $('.step-item').css('width', document.body.clientWidth / n + 'px')

        var str = [];
        var typeArr = new Object();
        getType();
        //获取商品类型
        function getType() {
            $.ajax({
                type: 'POST',
                url: "{:url('index/goodsType')}",
                data: {},
                dataType: 'json',
                async: false,
                success: function (Json) {
                    if (Json.code == 200) {
                        typeArr = Json.data.type_list;
                        for (var i = 0; i < typeArr.length; ++i) {
                            str.push(typeArr[i].gt_name)
                        }
                    }
                }
            });
        }
        $("#good_type").picker({
            cols: [
                {
                    textAlign: 'center',
                    values: str,
                    cssClass: 'picker-items-col-normal'
                }
            ]
        });

        $(document).on('touchend', '#submit', function () {
            var poliecy = $("input[ name='policy_num']").val();
            var p_id = $("input[ name='p_id']").val();
            var goods_name = $("input[ name='goods_name']").val();
            var goods_num = $("input[ name='goods_num']").val();
            var good_price = $("input[ name='good_price']").val();
            var good_pg_price = $("input[ name='good_pg_price']").val();
            var goods_type = $("#good_type").val();
            if (goods_name.length == 0) {
                $.alert('请填写货品名称');
                return;
            }
            if (goods_num.length == 0) {
                $.alert('请填写数量与规格');
                return;
            }
            if (good_price.length == 0) {
                $.alert('请填写物品原值');
                return;
            }
            if (good_pg_price.length == 0) {
                $.alert('请填写评估价');
                return;
            }

            for (var i = 0; i < typeArr.length; ++i) {
                if(goods_type ==typeArr[i].gt_name){
                    goods_type =typeArr[i].gt_id
                }
            }
            $.ajax({
                type: 'POST',
                url: "{:url('Insurer/update')}",
                data: {
                    'policy_num':poliecy,
                    'goods_type': goods_type,
                    'goods_name': goods_name,
                    'goods_num': goods_num,
                    'good_price': good_price,
                    'good_pg_price': good_pg_price,
                },
                dataType: 'json',
                success: function (Json) {

                    if (Json.code == 200) {
                        $.alert('保存成功');
                        location.href="{:url('Insurer/insurerInfo')}?p_id="+p_id;
                    } else {
                        $.alert('保存失败');
                    }
                }
            });


        });
    });

</script>
</html>